
global name "A0_cash_prepare_recall"
cap log close
log using "${pfile}/${name}.smcl", replace smcl


************ // RECALL PAYMENT YEAR 2015 - ELIGIBLITY YEAR 2014 // *************
use A0_cash_elig, clear

keep if year==2014

merge m:1 cpf using A0_cash_entry.dta, keepus(yf_min) keep(1 3) nogen
replace yf_min = 2000 if yf_min ==.

keep if abs(x)<=0.6
keep if wkd >= 31  // Abono eligibility (1)
keep if year >= yf_min+5  // Abono eligibility (3)

format pis %13.0g
tostring pis, g(pis6) format("%13.0f")
replace pis6 = substr(pis6,4,6) if length(pis6) == 11
replace pis6 = substr(pis6,3,6) if length(pis6) == 9
replace pis6 = substr(pis6,2,6) if length(pis6) == 7

rename p_id id // id of job spell defining cash bonus eligibility in 2014

g uf = int(p_mun/10^4)

keep year id pis pis6 uf x 

* recovering worker's name
merge m:1 year id using "${prais}/2014/1_2014s.dta", keep(1 3) keepus(nome) nogen

rename nome nometrabalhador
split nometrabalhador, l(9)

merge m:1 pis6 uf nometrabalhador1 nometrabalhador2 nometrabalhador3 nometrabalhador4 nometrabalhador5 nometrabalhador6 nometrabalhador7  ///
nometrabalhador8 using "${pabono}/Recall_2015/abono_recall2015.dta", nogen keep(1 3) keepus(co bank)

g abono = bank == "CAIXA" // workers in the private sector receive abono through Caixa Economica Federal Bank

gcollapse abono , by(x) fast

save FS2014.dta, replace




*********** // 

// *** // Share earning above 2 m.w. in any month // *** //
use "${prais}/2013/1_2013wageall", clear

keep pis cpf mun tpvinculo causadesli dt_hir w1 w2 w3 w4 w5 w6 w7 w8 w9 w10 w11 w12

sort pis cpf mun tpvinculo causadesli dt_hir 
by pis cpf mun tpvinculo causadesli dt_hir: g co = _n
drop if co >1
drop co

save "A0_wage2013temp.dta", replace


use A0_cash_elig, clear

keep if year==2013

merge m:1 cpf using A0_cash_entry.dta, keepus(yf_min) keep(1 3) nogen
replace yf_min = 2000 if yf_min ==.

keep if abs(x)<=0.6
keep if wkd >= 31  // Abono eligibility (1)
keep if year >= yf_min+5  // Abono eligibility (3)

rename p_mun mun
rename p_tpvinculo tpvinculo 
rename p_causadesli causadesli 
rename p_dt_hir dt_hir

keep pis cpf mun tpvinculo causadesli dt_hir x

merge m:1 pis cpf mun tpvinculo causadesli dt_hir using A0_wage2013temp.dta, ///
keepus(w1 w2 w3 w4 w5 w6 w7 w8 w9 w10 w11 w12) nogen keep(1 3)

g above = w1>2*678|w2>2*678|w4>2*678|w5>2*678|w6>2*678|w7>2*678|w8>2*678|w9>2*678|w1>10*678|w1>11*678|w1>12*678
g above_p10 = w1>2*678*1.1|w2>2*678*1.1|w4>2*678*1.1|w5>2*678*1.1|w6>2*678*1.1|w7>2*678*1.1|w8>2*678*1.1|w9>2*678*1.1|w1>10*678|w1>11*678|w1>12*678*1.1

gcollapse above_p10 above, by(x) fast

save FS2013.dta, replace

erase "A0_wage2013temp.dta"






cap log close